package demo1;

import sun.text.normalizer.UCharacter;

public class Test {
    public static void main(String[] args) {

        String str1 = "nishi";
        String str2 = "nishi";
        String str3 = new String("hello");//这种直接new的字符串类型直接比较引用是错误的
        String str4 = new String("hello");


        System.out.println(str1 == str2);
        System.out.println(str3.equals(str4));
        System.out.println(str3.compareTo(str4));

        //字符串查找的方法几乎都是实例方法
        System.out.println(str1.charAt(1));//返回字符串下标为1位置出现的字符
        System.out.println(str1.indexOf('c'));
        System.out.println(str1.charAt(0));
        System.out.println(str1.indexOf("n"));


        //数值转字符串
        String str7 = "121";
        String str8 = "121.666";
        System.out.println(String.valueOf(str7));
        System.out.println(String.valueOf(str8));


        //字符串转数值
        System.out.println(Integer.parseInt("7777"));
        System.out.println(Double.parseDouble("999.999"));
        System.out.println(Double.parseDouble("11.34"));
        System.out.println(Integer.parseInt("11"));
        //大小写转换
        String str5 = "nihao";
        String str9 = str5.toUpperCase();
        System.out.println(str9);
        System.out.println(str5.toUpperCase());

        //字符串转数组
        String str6 = "hello";
        char[] ch = str6.toCharArray();//转为字符数组要用字符数组来接收
        System.out.println(str6.toCharArray());
        System.out.println(ch[0]);

        //字符数组转字符串
        char[] chars = {'s','b','s','s'};
        String str10 = new String(chars);

        //字符串替换

        System.out.println(str10.replace('s','b'));

        String str11 = "yang&biao&666\\777000";
        String[] strings1 = str11.split("\\\\",2);//将字符串分为两组
//        System.out.println(strings1[0]);
//        System.out.println(strings1[1]);
        //含有多个分割符时用|连接
        String[] strings2 = str11.split("\\\\|&");
        System.out.println(strings2[0]);
        System.out.println(strings2[1]);
        System.out.println(strings2[2]);
        System.out.println(strings2[3]);
//        for (String x:strings) {
//
//            String[] ss = x.split("==");
//            for (String s:ss) {
//                System.out.println(s);
//            }

//            System.out.println(x);


        String str12 = "helloworld";
        System.out.println(str12.substring(0,5));
        }

    }

